package day03.homework.expand;

import java.util.Scanner;

public class DaysDemo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int days;
        while (true) {
            System.out.println("请输入年份：（输入0退出）");
            int year = scanner.nextInt();
            if (year == 0) {
                break;
            } else if (year < 0) {
                System.out.println("年份格式输入不正确，请重新输入");
                continue;
            }
            System.out.println("请输入月份：");
            int month = scanner.nextInt();

            switch (month) {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    days = 31;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    days = 30;
                    break;
                case 2:
                    days = 28;
                    break;
                default:
                    System.out.println("月份格式输入不正确，请重新输入");
                    continue;
            }

            if (month == 2) {
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                    days++;
                }
            }
            System.out.println(year + "年" + month + "月有" + days + "天");
        }
    }
}
